package cn.com.elite;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URLDecoder;
import java.util.Date;
import java.util.Iterator;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

public class HTPayGetResultService extends HttpServlet{
	private static final Log log=LogFactory.getLog(HTPayGetResultService.class);
	
	private String getERRO(Exception e){
		String str="";
		try{
            StringWriter sw=new StringWriter();  
            e.printStackTrace(new PrintWriter(sw,true));  
            str=sw.toString(); 	
		}catch(Exception e1){
			str=e.toString();
			log.error("getERRO:"+e1.toString());
		}
		return str;
	}
	public static void main(String[] args){
		String OrderNo="121000016085562012122516361890589|202012122500070839";
		String[] OrderNo_list=OrderNo.split("\\|");
		System.out.println("OrderNo.length:"+OrderNo.length());
		System.out.println("OrderNo_list.length:"+OrderNo_list.length);
		System.out.println("OrderNo_list[0]:"+OrderNo_list[0]);
		
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException{
		log.info("-------------------HTPayGetResultService------------------------------");
		request.setCharacterEncoding("GBK");
		String RespCode=request.getParameter("RespCode");
		log.info("RespCode:"+RespCode);
		String Remark=request.getParameter("Remark"); 
		Remark=URLDecoder.decode(Remark,"GBK");
		log.info("Remark:"+Remark);
		String TerminalNo=request.getParameter("TerminalNo");
		log.info("TerminalNo:"+TerminalNo);
		String MerchantNo=request.getParameter("MerchantNo");
		log.info("MerchantNo:"+MerchantNo);
		String OrderNo=request.getParameter("OrderNo");
		log.info("OrderNo:"+OrderNo);
		String[] OrderNo_list=OrderNo.split("\\|"); 
		log.info("OrderNo_list:"+OrderNo_list);
		OrderNo=OrderNo_list[0];
		log.info("OrderNo_pro:"+OrderNo);
		String OrderState=request.getParameter("OrderState");
		log.info("OrderState:"+OrderState);
		String Description=request.getParameter("Description");
		log.info("Description:"+Description);
		String ValidTime=request.getParameter("ValidTime");
		log.info("ValidTime:"+ValidTime);
		String OrderType=request.getParameter("OrderType");
		log.info("OrderType:"+OrderType);
		String TransData=request.getParameter("TransData");
		TransData=URLDecoder.decode(TransData,"GBK");
		log.info("TransData:"+TransData);
		String Mac=request.getParameter("Mac");
		log.info("Mac:"+Mac);
//		String Reference=request.getParameter("Reference");
//		log.info("Reference:"+Reference);
		
		String COM_CODE=HTPayService.ebean.chaxunString(" select HTPay_Getagency('"+OrderNo+"') from dual");
		log.info("COM_CODE:"+COM_CODE);
		
		String HG13=HTPayService.ebean.HTPay_log("",OrderNo,RespCode,"13");
        if(RespCode.equals("0000")){
        	HTPayService.getJyCgProcess(OrderNo,"",COM_CODE,HTPayService.USER,HTPayService.PASSWORD);      	
        }else if(RespCode.equals("00A3")){
     	    
        }else{
        	HTPayService.getJyCxProcess(OrderNo,"",COM_CODE,HTPayService.USER,HTPayService.PASSWORD);
        }
        
	}
	public void doGet(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException{
		this.doPost(request, response);
	}
	
}
